package com.cskaoyan.controller.wx_comment;

import com.cskaoyan.bean.wx_comment.Comment;
import com.cskaoyan.bean.wx_comment.vo.CommentCountVo;
import com.cskaoyan.bean.wx_comment.vo.CommentListVo;
import com.cskaoyan.bean.wx_resp.WxRespVo;
import com.cskaoyan.service.wx_comment.WxCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 类<code>Doc</code>用于：TODO
 *
 * @author Acher
 * @version 1.0
 * @date 2021-10-23
 */
@RequestMapping("wx/comment")
@RestController
public class CommentController {


    @Autowired
    WxCommentService wxCommentService;

    @RequestMapping("count")
    // http://localhost:8083/wx/comment/count?valueId=1181021&type=0
    public WxRespVo count(Comment comment) {
        CommentCountVo commentCountVo = wxCommentService.count(comment);
        return WxRespVo.ok(commentCountVo);
    }

    @RequestMapping("list")
    // http://localhost:8083/wx/comment/list?valueId=1181000&type=0&limit=20&page=1&showType=0
    public WxRespVo list(Comment comment) {
        // showType: module -> hasPic
        CommentListVo commentListVo = wxCommentService.list(comment);
        return WxRespVo.ok(commentListVo);
    }

    @PostMapping("post")
    // http://localhost:8083/wx/comment/post
    public WxRespVo post(@RequestBody Comment comment) {
        // showType: module -> hasPic
        if (!wxCommentService.add(comment))
            return WxRespVo.error("添加失败");
        return WxRespVo.ok(comment);
    }
}
